# !/usr/bin/env python3
# coding=utf8
"""
因为不太理解"净值回撤"图, 所以自己造了一份行情数据, 用 BuyAndHold 策略回测这一份数据, 有助于理解"净值回撤"图,
"""
import datetime
import numpy
import typing


def generate_price():
    """"""
    delta_s: typing.List[int] = [
        +0, +0, +0,
        +1, +1, +1, +1,
        +0, +0, +0,
        +1, +1, +1, +1,
        -1, -1, +1, +1,  # V形
        +1, +1, +1,
        -1, -1, +0, +0, +1, +1,  # 梯形
        +1, +1, +1, +1,
        -1, -1, +1, -1, +1, +1,  # W形
        +1, +1, +1, +1,
        +0, +0, +0,  # 中期高点
        -1, -1, -1,
        +0, +0, +0,
        -1, -1,
        -1, -1, +1, +1,  # V形
        -1,
        -1, -1, +1, +1,  # V形
        -1,
        -1, -1, +1, +1,  # V形
        +1, +1, +1, +1, +1, +1, +1,  # 重回中期高点
        +0, +0, +0,
        -1, -1, +1, +1,  # V形
        +0, +0, +0,
        +1, +1, +1,
        +0, +0, +0,
    ]

    base_price: int = 1000

    price_s: typing.List[int] = [base_price]
    for delta in delta_s:
        price = price_s[-1] + delta * 100
        price_s.append(price)

    return price_s


def generate_file():
    """"""
    price_s: list = generate_price()

    begDate: datetime.date = datetime.date(year=2022, month=1, day=1)
    endDate: datetime.date = begDate+datetime.timedelta(days=len(price_s))

    date_s = numpy.arange(start=begDate, stop=endDate)

    assert len(price_s) == len(date_s)

    filepath: str = __file__ + ".csv"

    with open(filepath, mode="w", encoding="UTF-8") as f:
        f.write("exchange,symbol,interval,datetime,open,high,low,close,volume,turnover,open_interest\n")

        exchange = "LOCAL"
        symbol = "TEST"
        interval = "DAILY"

        for i in range(0, len(price_s), 1):
            date: numpy.datetime64 = date_s[i]
            dddd: datetime.datetime = date.astype(datetime.datetime)
            dttm: str = dddd.strftime("%Y-%m-%d %H:%M:%S")

            Open = high = low = close = price_s[i]
            volume = turnover = open_interest = 0

            line: str = f"{exchange},{symbol},{interval},{dttm},{Open},{high},{low},{close},{volume},{turnover},{open_interest}\n"
            f.write(line)


if __name__ == "__main__":
    generate_file()
